package com.vcredit.creditcat.service;

import com.vcredit.creditcat.framework.pagination.DefaultCriteria;
import com.vcredit.creditcat.framework.pagination.Page;
import com.vcredit.creditcat.model.RegisterChannel;
import com.vcredit.creditcat.persistence.base.RegisterChannelMapper;
import com.vcredit.creditcat.vo.BuiSelectVo;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 **/
@Service
public class RegisterChannelService {

  @Autowired
  private RegisterChannelMapper mapper;

  public void insert(RegisterChannel obj) {
    mapper.insert(obj);
  }

  public void update(RegisterChannel obj) {
    mapper.update(obj);
  }

  public List<RegisterChannel> findAll() {
    return mapper.findAll();
  }

  public List<RegisterChannel> find(RegisterChannel obj) {
    return mapper.find(obj);
  }

  public Page<RegisterChannel> findByPage(DefaultCriteria criteria) {
    long num = mapper.findByPageCount(criteria);
    List<RegisterChannel> result = mapper.findByPage(criteria);
    return new Page<RegisterChannel>(num, result);
  }

  public List<BuiSelectVo> listAllChannel() {
    List<RegisterChannel> channelList = mapper.findAll();
    List<BuiSelectVo> buiSelectVos = new ArrayList<>(channelList.size());
    for (RegisterChannel item :
        channelList) {
      buiSelectVos.add(new BuiSelectVo(item.getChannelDesc(), item.getChannel()));
    }
    return buiSelectVos;
  }
}